package com.msb.system.service.impl;


import com.msb.system.entity.UserEntity;
import com.msb.system.info.UserInfo;
import com.msb.system.repostitory.UserRepository;
import com.msb.system.service.UserService;
import com.msb.system.util.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserRepository userRepository;

    @Override
    public boolean addUser(UserEntity userEntity) {
        UserInfo userInfo = ConvertUtil.userEntityConvertUserInfo(userEntity);
        userEntity.setUpass(DigestUtils.md5DigestAsHex(userEntity.getUpass().getBytes()));
        UserInfo user = userRepository.save(userInfo);

        return false;
    }

    @Override
    public boolean delUser(String ids) {
        String[] idList = ids.split(",");
        try {
            for (String id : idList) {
                UserInfo userInfo = userRepository.findById(Long.valueOf(id)).get();
                userInfo.setUstatus(1);
                userRepository.save(userInfo);
            }
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
}
